﻿
namespace MagicTrick

[<AutoOpen>]
module ConsoleReader =
    let readLine = System.Console.ReadLine

    let readInt() = int (readLine())

module MagicTrick =
    let readLine() =
        readLine().Split([|" "|], System.StringSplitOptions.RemoveEmptyEntries)
        |> Array.map (fun x -> int x)

    let getData() =
        let row = readInt()
        let cards = 
            Seq.init 4 (fun x -> readLine())
        row, (List.ofSeq cards)

    let getRow (x, (rows: 'a list)) =
        rows.[x-1]

    let solveCase() =
        let d1 = getData()
        let d2 = getData()

        let intersection = Set.intersect (Set.ofArray (getRow d1)) (Set.ofArray (getRow d2)) |> Seq.toList
        match intersection with
        | [] -> "Volunteer cheated!"
        | [x] -> string x
        | _::_ -> "Bad magician!"


    let solveCases nbOfCases =
        for i=1 to nbOfCases do
            printfn "Case #%d: %s" i (solveCase())